/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package glamourbeautyclinic.personel;

import glamourbeautyclinic.FrmHome;
import glamourbeautyclinic.service.FrmSerApp;
import java.awt.Dimension;
import java.awt.Toolkit;
import images.GlamourImage;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.swing.JDesktopPane;
import javax.swing.JFileChooser;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;
import javax.swing.RowSorter;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
import util.DBConnection;
import java.sql.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import javax.imageio.ImageIO;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;

public class FrmStaff_Hung extends javax.swing.JInternalFrame {

    //Declare for EVERY form
    GlamourImage GI = new GlamourImage();
    DBConnection dc;
    ResultSet rs;
    Statement stmt;
    String sql;
    DefaultTableModel staffModel;
    DefaultListModel<String> specModel;
    //Declare for CONCRETE form
    boolean isUpdate = false, isInsert = false, active, lock, isRowSelected = false;
    boolean isSelectAll = false, PictureChanged = false, isView = false;
    int rowCounter;
    String ID, name, Addr, newID, imgName = "NoImage", User, date;
    BufferedImage img;

    /**
     * Creates new form frmSearchCustomer
     */
    public FrmStaff_Hung(DBConnection dc) {
        initComponents();
        try {
            stmt = dc.con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        this.dc = dc;
        GI.addIconFor(this);
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        // Can be resize height parameter to proper scale
        this.setLocation((screenSize.width - this.getWidth()) / 2 - 100, 10);
        RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tblStaff.getModel());
        tblStaff.setRowSorter(sorter);
        tblStaff.setComponentPopupMenu(pmnStaff);
        //----------------------------------
        FrmHome home = new FrmHome();
        User = home.user;
//        Field var;
//        try {
//            var = getDesktopPane().getTopLevelAncestor().getClass().getField("User");
//            String User = (String)var.get(getDesktopPane().getTopLevelAncestor());
//            
//        } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex) {
//            Logger.getLogger(FrmCustomer.class.getName()).log(Level.SEVERE, null, ex);
//        }
        //----------------------------------
        DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
        Calendar cal = Calendar.getInstance();
        date = dateFormat.format(cal.getTime());
        staffModel = (DefaultTableModel) tblStaff.getModel();
        specModel = new DefaultListModel<>();

        tblStaff.setModel(staffModel);
        beginState();
        try {
            tblStaff.setDefaultRenderer(Object.class, new MyRender());
            staffModel.addTableModelListener(new TableModelListener() {
                @Override
                public void tableChanged(TableModelEvent e) {
                    int row = tblStaff.getSelectedRow();
                    if (row != -1) {
                        row = tblStaff.convertRowIndexToModel(row);
                    }
                    if (e.getColumn() == 2 || e.getColumn() == 3) {
                        //<editor-fold defaultstate="collapsed" desc="Lock and Active process">
                        boolean lockCliked = false, activeClicked = false;
                        // isActive = false when lock Staff
                        if (e.getColumn() == 3) {
                            if (tblStaff.getSelectedColumn() == 3) {
                                lockCliked = true;
                            }
                            if (staffModel.getValueAt(row, 3).equals(true)) {
                                int ans = JOptionPane.showConfirmDialog(null, "Are you sure to lock this staff?", "Warning", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                                if (ans != JOptionPane.YES_OPTION) {
                                    staffModel.setValueAt(false, row, 3);
                                    return;
                                } else {
                                    if (staffModel.getValueAt(row, 2).equals(true) && lockCliked) {
                                        staffModel.setValueAt(false, row, 2);// Set active to false 
                                    }
                                    sql = "Update Staff set Active=0 , isLock=1, usermodified='" + User
                                            + "', DateModified='" + date
                                            + "' where StaffID='" + String.valueOf(staffModel.getValueAt(row, 4)) + "'";
                                }
                            } else {
                                sql = "Update Staff set isLock=0, UserModified='" + User
                                        + "', DateModified='" + date
                                        + "' where StaffID='" + String.valueOf(staffModel.getValueAt(row, 4)) + "'";
                            }
                        }
                        // Active action processing
                        String isActive = staffModel.getValueAt(row, 2).equals(true) ? "1" : "0";
                        if (e.getColumn() == 2) {
                            if (tblStaff.getSelectedColumn() == 2) {
                                activeClicked = true;
                            }
                            if (staffModel.getValueAt(row, 3).equals(true) && staffModel.getValueAt(row, 2).equals(true) && activeClicked) { // Cannot active lock Staff
                                JOptionPane.showMessageDialog(null, "Cannot active Locked staff", "Warning", JOptionPane.WARNING_MESSAGE);
                                staffModel.setValueAt(false, row, 2);
                                repaint();
                                return;
                            } else {
                                sql = "Update Staff set Active="
                                        + isActive
                                        + ", UserModified='" + User + "', DateModified='" + date
                                        + "' where StaffID='" + String.valueOf(staffModel.getValueAt(row, 4)) + "'";
                            }
                        }
                        try {
                            stmt.executeUpdate(sql);
                        } catch (SQLException ex) {
                            System.out.println("No SQL execution");
                        }
                        repaint();
                        //</editor-fold>
                    }
                    if (e.getColumn() == 0) {
                        //<editor-fold defaultstate="collapsed" desc="Select process">
                        //Find RowSelected or not, SelectAll or not
                        boolean flag = false;
                        boolean flag_uncheck = false;
                        rowCounter = 0;
                        for (int i = 0; i < staffModel.getRowCount(); i++) {
                            if (staffModel.getValueAt(i, 0).equals(true)) {
                                flag = true;
                                rowCounter++;
                            } else {
                                flag_uncheck = true;
                            }
                        }
                        isRowSelected = flag;
                        isSelectAll = !flag_uncheck;
                        btnSelectAll.setEnabled(!isSelectAll);
                        btnDeselect.setEnabled(isRowSelected);
                        if (rowCounter >= 2) {
                            btnEmp_App.setEnabled(false);
                            specModel.clear();
                            btnAddSpec.setEnabled(false);
                            btnLockStaff.setEnabled(true);
                            btnUnlockStaff.setEnabled(true);
                        }
                        //--------------------
                        //</editor-fold>  
                    }

                }
            });
            //
            tblStaff.removeColumn(tblStaff.getColumnModel().getColumn(6));
            tblStaff.removeColumn(tblStaff.getColumnModel().getColumn(5));
            tblStaff.removeColumn(tblStaff.getColumnModel().getColumn(4));

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    //<editor-fold defaultstate="collapsed" desc="Method Group">
    public void addTableValue(String sql) {
        try {
            rs = stmt.executeQuery(sql);
            while (rs.next()) {
                Object[] row = {false,
                    rs.getString(2),
                    (rs.getByte(4) == 1),
                    (rs.getByte(5) == 1),
                    rs.getString(1), // StaffID
                    rs.getString(3), // Address
                    rs.getString(6) // Img
            };
                staffModel.addRow(row);
            }
            // Set record label
            int temp = tblStaff.getModel().getRowCount();
            if (temp >= 2) {
                lblStaffFound.setText(temp + " records found");
            } else {
                lblStaffFound.setText(temp + " record found");
            }//
            if (staffModel.getRowCount() == 0) {
                btnSelectAll.setEnabled(false);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void noSelectionState() {
        btnDeselect.setEnabled(false);
        btnLockStaff.setEnabled(false);
        btnUnlockStaff.setEnabled(false);
        btnEmp_App.setEnabled(false);
        btnAddSpec.setEnabled(false);
        btnUpdate.setEnabled(false);
        specModel.clear();
    }

    private void beginState() {
        // Search region
        txtStaffID_S.setText("");
        txtStaffName_S.setText("");
        chkActive_S.setSelected(true);
        txtStaffID_S.setEditable(false);
        txtStaffName_S.grabFocus();
        btnSearch.setEnabled(false);
        // Details region
        btnDeselect.setEnabled(false);
        txtAddress_D.setText("");
        txtAddress_D.setEditable(false);
        txtStaffID_D.setText("");
        txtStaffID_D.setEditable(false);
        txtStaffName_D.setText("");
        txtStaffName_D.setEditable(false);
        chkActive.setSelected(false);
        chkLock.setSelected(false);
        chkActive.setEnabled(false);
        chkLock.setEnabled(false);
        btnAddSpec.setEnabled(false);
        btnEmp_App.setEnabled(false);
        imgStaff.setIcon(null);
        //----------------------------
        btnLockStaff.setEnabled(false);
        btnUnlockStaff.setEnabled(false);
        btnUpdate.setEnabled(false);
        btnAddImg.setEnabled(false);
        btnSave.setEnabled(false);
        btnCancel.setEnabled(false);
        if (isInsert || isUpdate) {
            imgName = "NoImage";
            isInsert = false;
            isUpdate = false;
            PictureChanged = false;
            btnInsert.setEnabled(true);
        } else {
            //<editor-fold defaultstate="collapsed" desc="Load table data">
            try {
                tblStaff.getSelectionModel().clearSelection();
                staffModel.setRowCount(0);
                addTableValue("select * from staff where active =1");
                // Generate a newID for insert later
                rs = stmt.executeQuery("select * from staff");
                if (!rs.isBeforeFirst()) {
                    newID = "Emp0001";
                } else {
                    rs.last();
                    if (rs.isLast()) {
                        String temp = rs.getString(1);
                        temp = temp.substring(3, 7);
                        int tempNum = Integer.parseInt(temp) + 1;
                        temp = String.valueOf(tempNum);
                        temp = (tempNum < 10) ? "000" + temp
                                : (tempNum < 100) ? "00" + temp
                                        : (tempNum < 1000) ? "0" + temp : temp;
                        newID = "Emp" + temp;
                    }
                }
                //
            } catch (Exception e) {
                e.printStackTrace();
            }
//</editor-fold>
        }
        // Load data for table

    }

    private void openfield(String s) {
        txtAddress_D.setEditable(true);
        txtStaffName_D.setEditable(true);
        chkActive.setEnabled(true);
        chkLock.setEnabled(true);
        btnAddImg.setEnabled(true);
        btnSave.setEnabled(true);
        btnCancel.setEnabled(true);
        if (s.equalsIgnoreCase("insert")) {
            txtAddress_D.setText("");
            txtStaffID_D.setText("");
            txtStaffName_D.setText("");
            imgStaff.setIcon(null);
        }
    }

    public String checkField() {
        name = txtStaffName_D.getText();
        Addr = txtAddress_D.getText();
        if (name.equals("")) {
            txtStaffName_D.grabFocus();
            return "Staff name cannot be blank";
        } else if (name.length() > 50) {
            txtStaffName_D.grabFocus();
            return "Staff name cannot have more than 50 characters";
        }
        // Address field
        if (Addr.equals("")) {
            txtAddress_D.grabFocus();
            return "Address cannot be blank";
        } else if (Addr.length() > 100) {
            txtAddress_D.grabFocus();
            return "Address cannot have more than 100 characters";
        }
        return "";
    }
    //</editor-fold>

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pmnStaff = new javax.swing.JPopupMenu();
        mniNew = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JPopupMenu.Separator();
        mniUpdate = new javax.swing.JMenuItem();
        mniAddSpec = new javax.swing.JMenuItem();
        mniLock = new javax.swing.JMenuItem();
        mniUnlock = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        mniSelectAll = new javax.swing.JMenuItem();
        mniDeselect = new javax.swing.JMenuItem();
        grpFilter = new javax.swing.ButtonGroup();
        btnDeleteSpec = new javax.swing.JButton();
        pnlLookup = new javax.swing.JPanel();
        radStaffID = new javax.swing.JRadioButton();
        jPanel1 = new javax.swing.JPanel();
        btnFindAll = new javax.swing.JButton();
        chkActive_S = new javax.swing.JCheckBox();
        radStaffName = new javax.swing.JRadioButton();
        txtStaffID_S = new javax.swing.JTextField();
        txtStaffName_S = new javax.swing.JTextField();
        btnSearch = new javax.swing.JButton();
        jSeparator = new javax.swing.JSeparator();
        btnSelectAll = new javax.swing.JButton();
        btnDeselect = new javax.swing.JButton();
        btnLockStaff = new javax.swing.JButton();
        btnUnlockStaff = new javax.swing.JButton();
        btnEmp_App = new javax.swing.JButton();
        jspStaff = new javax.swing.JScrollPane();
        tblStaff = new javax.swing.JTable();
        lblStaffFound = new javax.swing.JLabel();
        lblSpec = new javax.swing.JLabel();
        jspSpec = new javax.swing.JScrollPane();
        lstSpec = new javax.swing.JList();
        btnAddSpec = new javax.swing.JButton();
        pnlDetails = new javax.swing.JPanel();
        btnInsert = new javax.swing.JButton();
        btnUpdate = new javax.swing.JButton();
        pnlDetailsChild = new javax.swing.JPanel();
        lblStaffID = new javax.swing.JLabel();
        txtStaffID_D = new javax.swing.JTextField();
        lblStaffName = new javax.swing.JLabel();
        lblRequired2 = new javax.swing.JLabel();
        txtStaffName_D = new javax.swing.JTextField();
        lblAddr = new javax.swing.JLabel();
        lblRequired3 = new javax.swing.JLabel();
        txtAddress_D = new javax.swing.JTextField();
        lblStatus = new javax.swing.JLabel();
        chkActive = new javax.swing.JCheckBox();
        chkLock = new javax.swing.JCheckBox();
        imgStaff = new javax.swing.JLabel();
        btnAddImg = new javax.swing.JButton();
        lblDetailsMsg = new javax.swing.JLabel();
        btnSave = new javax.swing.JButton();
        btnCancel = new javax.swing.JButton();
        btnExit = new javax.swing.JButton();

        pmnStaff.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
                pmnStaffPopupMenuWillBecomeVisible(evt);
            }
        });

        mniNew.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Insert.png"))); // NOI18N
        mniNew.setText(" New staff");
        mniNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mniNewActionPerformed(evt);
            }
        });
        pmnStaff.add(mniNew);
        pmnStaff.add(jSeparator2);

        mniUpdate.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Update.png"))); // NOI18N
        mniUpdate.setText("Update staff");
        mniUpdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mniUpdateActionPerformed(evt);
            }
        });
        pmnStaff.add(mniUpdate);

        mniAddSpec.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Insert.png"))); // NOI18N
        mniAddSpec.setText("New specialist");
        mniAddSpec.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mniAddSpecActionPerformed(evt);
            }
        });
        pmnStaff.add(mniAddSpec);

        mniLock.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Lock.png"))); // NOI18N
        mniLock.setText("Lock");
        pmnStaff.add(mniLock);

        mniUnlock.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Unlock.png"))); // NOI18N
        mniUnlock.setText("Unlock");
        pmnStaff.add(mniUnlock);
        pmnStaff.add(jSeparator1);

        mniSelectAll.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/SelectAll.png"))); // NOI18N
        mniSelectAll.setText("Select all");
        mniSelectAll.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mniSelectAllActionPerformed(evt);
            }
        });
        pmnStaff.add(mniSelectAll);

        mniDeselect.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Deselect.png"))); // NOI18N
        mniDeselect.setText("Deselect");
        mniDeselect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mniDeselectActionPerformed(evt);
            }
        });
        pmnStaff.add(mniDeselect);

        btnDeleteSpec.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Delete.png"))); // NOI18N
        btnDeleteSpec.setToolTipText("Delete specialist");
        btnDeleteSpec.setBorderPainted(false);
        btnDeleteSpec.setContentAreaFilled(false);
        btnDeleteSpec.setEnabled(false);
        btnDeleteSpec.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeleteSpecActionPerformed(evt);
            }
        });

        setClosable(true);
        setIconifiable(true);
        setTitle("Staff management");
        setMaximumSize(new java.awt.Dimension(672, 634));
        setName("Staff"); // NOI18N
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameClosing(evt);
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameDeiconified(evt);
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameIconified(evt);
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
            }
        });

        pnlLookup.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true), "Search", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12), new java.awt.Color(51, 51, 51))); // NOI18N
        pnlLookup.setOpaque(false);

        radStaffID.setBackground(new java.awt.Color(255, 255, 255));
        grpFilter.add(radStaffID);
        radStaffID.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        radStaffID.setForeground(new java.awt.Color(0, 51, 255));
        radStaffID.setText("Staff ID");
        radStaffID.setBorder(null);
        radStaffID.setBorderPainted(true);
        radStaffID.setFocusPainted(false);
        radStaffID.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        radStaffID.setOpaque(false);
        radStaffID.setPreferredSize(new java.awt.Dimension(43, 20));
        radStaffID.setRolloverEnabled(false);
        radStaffID.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                radStaffIDPropertyChange(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        btnFindAll.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnFindAll.setForeground(new java.awt.Color(0, 51, 51));
        btnFindAll.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/SelectAll.png"))); // NOI18N
        btnFindAll.setMnemonic('S');
        btnFindAll.setText("Find All");
        btnFindAll.setToolTipText("Find customer");
        btnFindAll.setBorder(null);
        btnFindAll.setContentAreaFilled(false);
        btnFindAll.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnFindAll.setMargin(new java.awt.Insets(6, 6, 6, 6));
        btnFindAll.setName(""); // NOI18N
        btnFindAll.setOpaque(true);
        btnFindAll.setPreferredSize(new java.awt.Dimension(59, 22));
        btnFindAll.setRolloverEnabled(false);
        btnFindAll.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFindAllActionPerformed(evt);
            }
        });

        chkActive_S.setForeground(new java.awt.Color(0, 102, 51));
        chkActive_S.setSelected(true);
        chkActive_S.setText("Active Only");
        chkActive_S.setBorder(null);
        chkActive_S.setBorderPainted(true);
        chkActive_S.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        chkActive_S.setOpaque(false);
        chkActive_S.setPreferredSize(new java.awt.Dimension(51, 20));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addComponent(btnFindAll, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(chkActive_S, javax.swing.GroupLayout.DEFAULT_SIZE, 76, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnFindAll, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(chkActive_S, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 2, Short.MAX_VALUE))
        );

        radStaffName.setBackground(new java.awt.Color(255, 255, 255));
        grpFilter.add(radStaffName);
        radStaffName.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        radStaffName.setForeground(new java.awt.Color(0, 51, 255));
        radStaffName.setSelected(true);
        radStaffName.setText("Staff name");
        radStaffName.setBorder(null);
        radStaffName.setBorderPainted(true);
        radStaffName.setFocusPainted(false);
        radStaffName.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        radStaffName.setOpaque(false);
        radStaffName.setPreferredSize(new java.awt.Dimension(43, 20));
        radStaffName.setRolloverEnabled(false);
        radStaffName.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                radStaffNamePropertyChange(evt);
            }
        });

        txtStaffID_S.setEditable(false);
        txtStaffID_S.setForeground(new java.awt.Color(0, 102, 51));
        txtStaffID_S.setPreferredSize(new java.awt.Dimension(56, 20));
        txtStaffID_S.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtStaffID_SKeyReleased(evt);
            }
        });

        txtStaffName_S.setForeground(new java.awt.Color(0, 102, 51));
        txtStaffName_S.setPreferredSize(new java.awt.Dimension(56, 20));
        txtStaffName_S.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtStaffName_SKeyReleased(evt);
            }
        });

        btnSearch.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnSearch.setForeground(new java.awt.Color(0, 51, 51));
        btnSearch.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Search.png"))); // NOI18N
        btnSearch.setMnemonic('S');
        btnSearch.setText("Search");
        btnSearch.setToolTipText("Find staff");
        btnSearch.setBorder(null);
        btnSearch.setContentAreaFilled(false);
        btnSearch.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnSearch.setMargin(new java.awt.Insets(6, 6, 6, 6));
        btnSearch.setName(""); // NOI18N
        btnSearch.setOpaque(true);
        btnSearch.setPreferredSize(new java.awt.Dimension(59, 22));
        btnSearch.setRolloverEnabled(false);
        btnSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSearchActionPerformed(evt);
            }
        });

        btnSelectAll.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnSelectAll.setForeground(new java.awt.Color(0, 51, 51));
        btnSelectAll.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/SelectAll.png"))); // NOI18N
        btnSelectAll.setMnemonic('a');
        btnSelectAll.setText("Select all");
        btnSelectAll.setToolTipText("Check all select combo box");
        btnSelectAll.setBorder(null);
        btnSelectAll.setContentAreaFilled(false);
        btnSelectAll.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnSelectAll.setMargin(new java.awt.Insets(6, 6, 6, 6));
        btnSelectAll.setName(""); // NOI18N
        btnSelectAll.setOpaque(true);
        btnSelectAll.setPreferredSize(new java.awt.Dimension(59, 22));
        btnSelectAll.setRolloverEnabled(false);
        btnSelectAll.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSelectAllActionPerformed(evt);
            }
        });

        btnDeselect.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnDeselect.setForeground(new java.awt.Color(0, 51, 51));
        btnDeselect.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Deselect.png"))); // NOI18N
        btnDeselect.setMnemonic('e');
        btnDeselect.setText("Deselect");
        btnDeselect.setToolTipText("Uncheck all select combo box");
        btnDeselect.setBorder(null);
        btnDeselect.setContentAreaFilled(false);
        btnDeselect.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnDeselect.setMargin(new java.awt.Insets(6, 6, 6, 6));
        btnDeselect.setName(""); // NOI18N
        btnDeselect.setOpaque(true);
        btnDeselect.setPreferredSize(new java.awt.Dimension(59, 22));
        btnDeselect.setRolloverEnabled(false);
        btnDeselect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeselectActionPerformed(evt);
            }
        });

        btnLockStaff.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Lock.png"))); // NOI18N
        btnLockStaff.setToolTipText("Lock staff");
        btnLockStaff.setBorderPainted(false);
        btnLockStaff.setContentAreaFilled(false);
        btnLockStaff.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnLockStaff.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLockStaffActionPerformed(evt);
            }
        });

        btnUnlockStaff.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Unlock.png"))); // NOI18N
        btnUnlockStaff.setToolTipText("Unlock staff");
        btnUnlockStaff.setBorderPainted(false);
        btnUnlockStaff.setContentAreaFilled(false);
        btnUnlockStaff.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnUnlockStaff.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUnlockStaffActionPerformed(evt);
            }
        });

        btnEmp_App.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/001_25.png"))); // NOI18N
        btnEmp_App.setToolTipText("View appointment");
        btnEmp_App.setBorderPainted(false);
        btnEmp_App.setContentAreaFilled(false);
        btnEmp_App.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnEmp_App.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEmp_AppActionPerformed(evt);
            }
        });

        tblStaff.setAutoCreateRowSorter(true);
        tblStaff.setForeground(new java.awt.Color(0, 102, 51));
        tblStaff.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Select", "Name", "Active", "Lock", "StaffID", "Address", "Image"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Boolean.class, java.lang.Object.class, java.lang.Boolean.class, java.lang.Boolean.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                true, false, true, true, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tblStaff.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
        tblStaff.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        tblStaff.getTableHeader().setReorderingAllowed(false);
        tblStaff.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                tblStaffMousePressed(evt);
            }
        });
        jspStaff.setViewportView(tblStaff);
        if (tblStaff.getColumnModel().getColumnCount() > 0) {
            tblStaff.getColumnModel().getColumn(0).setPreferredWidth(30);
            tblStaff.getColumnModel().getColumn(1).setPreferredWidth(130);
            tblStaff.getColumnModel().getColumn(2).setPreferredWidth(70);
            tblStaff.getColumnModel().getColumn(3).setPreferredWidth(30);
        }

        lblStaffFound.setForeground(new java.awt.Color(0, 51, 255));
        lblStaffFound.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        lblStaffFound.setText("0 records found");
        lblStaffFound.setPreferredSize(new java.awt.Dimension(38, 20));

        lblSpec.setDisplayedMnemonic('n');
        lblSpec.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lblSpec.setForeground(new java.awt.Color(0, 51, 255));
        lblSpec.setLabelFor(txtStaffID_D);
        lblSpec.setText("Employee's specialist");
        lblSpec.setPreferredSize(new java.awt.Dimension(38, 20));

        lstSpec.setForeground(new java.awt.Color(0, 102, 51));
        lstSpec.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                lstSpecValueChanged(evt);
            }
        });
        jspSpec.setViewportView(lstSpec);

        btnAddSpec.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Update.png"))); // NOI18N
        btnAddSpec.setToolTipText("Insert new specialist");
        btnAddSpec.setBorderPainted(false);
        btnAddSpec.setContentAreaFilled(false);
        btnAddSpec.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddSpecActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlLookupLayout = new javax.swing.GroupLayout(pnlLookup);
        pnlLookup.setLayout(pnlLookupLayout);
        pnlLookupLayout.setHorizontalGroup(
            pnlLookupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlLookupLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlLookupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jSeparator)
                    .addGroup(pnlLookupLayout.createSequentialGroup()
                        .addGroup(pnlLookupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(pnlLookupLayout.createSequentialGroup()
                                .addComponent(lblStaffFound, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGap(216, 216, 216))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pnlLookupLayout.createSequentialGroup()
                                .addComponent(btnSelectAll, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnDeselect, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(79, 79, 79)
                                .addComponent(btnLockStaff, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnUnlockStaff, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnEmp_App, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 21, Short.MAX_VALUE))
                            .addComponent(jspStaff, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addGroup(pnlLookupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pnlLookupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(lblSpec, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jspSpec, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlLookupLayout.createSequentialGroup()
                                .addComponent(btnAddSpec, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(52, 52, 52)))))
                .addContainerGap())
            .addGroup(pnlLookupLayout.createSequentialGroup()
                .addGap(53, 53, 53)
                .addGroup(pnlLookupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(radStaffID, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(radStaffName, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlLookupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtStaffID_S, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(txtStaffName_S, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(pnlLookupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlLookupLayout.createSequentialGroup()
                        .addGap(36, 36, 36)
                        .addComponent(btnSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pnlLookupLayout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pnlLookupLayout.setVerticalGroup(
            pnlLookupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlLookupLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlLookupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlLookupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(radStaffID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txtStaffID_S, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(btnSearch, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlLookupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(pnlLookupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(radStaffName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txtStaffName_S, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addComponent(jSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(pnlLookupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlLookupLayout.createSequentialGroup()
                        .addGroup(pnlLookupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(pnlLookupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(btnSelectAll, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(btnDeselect, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(btnLockStaff, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnUnlockStaff, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnEmp_App, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnlLookupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jspSpec, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                            .addComponent(jspStaff, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(lblSpec, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlLookupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnAddSpec)
                    .addComponent(lblStaffFound, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(74, 74, 74))
        );

        pnlDetails.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true), "Details infomation", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12), new java.awt.Color(51, 51, 51))); // NOI18N
        pnlDetails.setOpaque(false);

        btnInsert.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnInsert.setForeground(new java.awt.Color(0, 51, 51));
        btnInsert.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Insert.png"))); // NOI18N
        btnInsert.setMnemonic('x');
        btnInsert.setText("Insert");
        btnInsert.setToolTipText("Save to database");
        btnInsert.setBorder(null);
        btnInsert.setContentAreaFilled(false);
        btnInsert.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnInsert.setMargin(new java.awt.Insets(6, 6, 6, 6));
        btnInsert.setName(""); // NOI18N
        btnInsert.setOpaque(true);
        btnInsert.setPreferredSize(new java.awt.Dimension(59, 22));
        btnInsert.setRolloverEnabled(false);
        btnInsert.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnInsertActionPerformed(evt);
            }
        });

        btnUpdate.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnUpdate.setForeground(new java.awt.Color(0, 51, 51));
        btnUpdate.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Update.png"))); // NOI18N
        btnUpdate.setMnemonic('x');
        btnUpdate.setText("Update");
        btnUpdate.setToolTipText("Save to database");
        btnUpdate.setBorder(null);
        btnUpdate.setContentAreaFilled(false);
        btnUpdate.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnUpdate.setMargin(new java.awt.Insets(6, 6, 6, 6));
        btnUpdate.setName(""); // NOI18N
        btnUpdate.setOpaque(true);
        btnUpdate.setPreferredSize(new java.awt.Dimension(59, 22));
        btnUpdate.setRolloverEnabled(false);
        btnUpdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUpdateActionPerformed(evt);
            }
        });

        pnlDetailsChild.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 102, 102)));

        lblStaffID.setDisplayedMnemonic('n');
        lblStaffID.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lblStaffID.setForeground(new java.awt.Color(0, 51, 255));
        lblStaffID.setLabelFor(txtStaffID_D);
        lblStaffID.setText("Staff ID");
        lblStaffID.setPreferredSize(new java.awt.Dimension(38, 20));

        txtStaffID_D.setForeground(new java.awt.Color(0, 102, 51));
        txtStaffID_D.setPreferredSize(new java.awt.Dimension(56, 20));

        lblStaffName.setDisplayedMnemonic('r');
        lblStaffName.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lblStaffName.setForeground(new java.awt.Color(0, 51, 255));
        lblStaffName.setText("Staff name");
        lblStaffName.setPreferredSize(new java.awt.Dimension(38, 20));

        lblRequired2.setForeground(new java.awt.Color(255, 51, 51));
        lblRequired2.setText("(*)");
        lblRequired2.setPreferredSize(new java.awt.Dimension(38, 20));

        txtStaffName_D.setForeground(new java.awt.Color(0, 102, 51));
        txtStaffName_D.setPreferredSize(new java.awt.Dimension(56, 20));

        lblAddr.setDisplayedMnemonic('r');
        lblAddr.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lblAddr.setForeground(new java.awt.Color(0, 51, 255));
        lblAddr.setText("Address");
        lblAddr.setPreferredSize(new java.awt.Dimension(38, 20));

        lblRequired3.setForeground(new java.awt.Color(255, 51, 51));
        lblRequired3.setText("(*)");
        lblRequired3.setPreferredSize(new java.awt.Dimension(38, 20));

        txtAddress_D.setForeground(new java.awt.Color(0, 102, 51));
        txtAddress_D.setPreferredSize(new java.awt.Dimension(56, 20));

        lblStatus.setDisplayedMnemonic('r');
        lblStatus.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lblStatus.setForeground(new java.awt.Color(0, 51, 255));
        lblStatus.setText("Status");
        lblStatus.setPreferredSize(new java.awt.Dimension(38, 20));

        chkActive.setForeground(new java.awt.Color(0, 102, 51));
        chkActive.setText("Active");

        chkLock.setForeground(new java.awt.Color(0, 102, 51));
        chkLock.setText("Lock");

        imgStaff.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        btnAddImg.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnAddImg.setForeground(new java.awt.Color(0, 51, 51));
        btnAddImg.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Insert.png"))); // NOI18N
        btnAddImg.setMnemonic('x');
        btnAddImg.setText("Add picture");
        btnAddImg.setToolTipText("Save to database");
        btnAddImg.setBorder(null);
        btnAddImg.setContentAreaFilled(false);
        btnAddImg.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnAddImg.setMargin(new java.awt.Insets(6, 6, 6, 6));
        btnAddImg.setName(""); // NOI18N
        btnAddImg.setOpaque(true);
        btnAddImg.setPreferredSize(new java.awt.Dimension(59, 22));
        btnAddImg.setRolloverEnabled(false);
        btnAddImg.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddImgActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlDetailsChildLayout = new javax.swing.GroupLayout(pnlDetailsChild);
        pnlDetailsChild.setLayout(pnlDetailsChildLayout);
        pnlDetailsChildLayout.setHorizontalGroup(
            pnlDetailsChildLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlDetailsChildLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlDetailsChildLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(lblStatus, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE)
                    .addComponent(lblStaffName, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblAddr, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblStaffID, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlDetailsChildLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblRequired2, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblRequired3, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnlDetailsChildLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtStaffID_D, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(pnlDetailsChildLayout.createSequentialGroup()
                        .addComponent(chkActive)
                        .addGap(18, 18, 18)
                        .addComponent(chkLock))
                    .addComponent(txtStaffName_D, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(txtAddress_D, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 62, Short.MAX_VALUE)
                .addGroup(pnlDetailsChildLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(imgStaff, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnAddImg, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(31, 31, 31))
        );
        pnlDetailsChildLayout.setVerticalGroup(
            pnlDetailsChildLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlDetailsChildLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlDetailsChildLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(pnlDetailsChildLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(pnlDetailsChildLayout.createSequentialGroup()
                            .addGap(114, 114, 114)
                            .addComponent(btnAddImg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(imgStaff, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pnlDetailsChildLayout.createSequentialGroup()
                        .addGroup(pnlDetailsChildLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblStaffID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtStaffID_D, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(pnlDetailsChildLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblStaffName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblRequired2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtStaffName_D, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(pnlDetailsChildLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblAddr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblRequired3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtAddress_D, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(pnlDetailsChildLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(pnlDetailsChildLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(chkActive)
                                .addComponent(chkLock)))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        lblDetailsMsg.setForeground(new java.awt.Color(255, 51, 51));
        lblDetailsMsg.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblDetailsMsg.setPreferredSize(new java.awt.Dimension(38, 20));

        btnSave.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnSave.setForeground(new java.awt.Color(0, 51, 51));
        btnSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Save.png"))); // NOI18N
        btnSave.setMnemonic('x');
        btnSave.setText("Save");
        btnSave.setToolTipText("Save to database");
        btnSave.setBorder(null);
        btnSave.setContentAreaFilled(false);
        btnSave.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnSave.setEnabled(false);
        btnSave.setMargin(new java.awt.Insets(6, 6, 6, 6));
        btnSave.setName(""); // NOI18N
        btnSave.setOpaque(true);
        btnSave.setPreferredSize(new java.awt.Dimension(59, 22));
        btnSave.setRolloverEnabled(false);
        btnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveActionPerformed(evt);
            }
        });

        btnCancel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnCancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Cancel.png"))); // NOI18N
        btnCancel.setText("Cancel");
        btnCancel.setBorderPainted(false);
        btnCancel.setContentAreaFilled(false);
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlDetailsLayout = new javax.swing.GroupLayout(pnlDetails);
        pnlDetails.setLayout(pnlDetailsLayout);
        pnlDetailsLayout.setHorizontalGroup(
            pnlDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlDetailsLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pnlDetailsChild, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(pnlDetailsLayout.createSequentialGroup()
                        .addComponent(btnInsert, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlDetailsLayout.createSequentialGroup()
                        .addComponent(lblDetailsMsg, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCancel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnSave, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        pnlDetailsLayout.setVerticalGroup(
            pnlDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlDetailsLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnInsert, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlDetailsChild, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnSave, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblDetailsMsg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCancel))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        btnExit.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnExit.setForeground(new java.awt.Color(0, 51, 51));
        btnExit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/quit.png"))); // NOI18N
        btnExit.setMnemonic('x');
        btnExit.setText("Exit");
        btnExit.setToolTipText("Close window");
        btnExit.setBorder(null);
        btnExit.setContentAreaFilled(false);
        btnExit.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnExit.setMargin(new java.awt.Insets(6, 6, 6, 6));
        btnExit.setName(""); // NOI18N
        btnExit.setOpaque(true);
        btnExit.setPreferredSize(new java.awt.Dimension(59, 22));
        btnExit.setRolloverEnabled(false);
        btnExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExitActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(pnlLookup, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pnlDetails, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnExit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(227, 227, 227))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pnlLookup, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlDetails, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
                .addComponent(btnExit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tblStaffMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblStaffMousePressed
        int rowSelected = tblStaff.getSelectedRow();
        if (rowSelected != -1) {
            rowSelected = tblStaff.convertRowIndexToModel(rowSelected);
            boolean state = staffModel.getValueAt(rowSelected, 3).equals(true);
            btnLockStaff.setEnabled(!state);
            btnUnlockStaff.setEnabled(state);
            btnAddSpec.setEnabled(!state);
            btnUpdate.setEnabled(true);
            btnEmp_App.setEnabled(true);
            //
            if (isView) {
                JDesktopPane desk = getDesktopPane();
                JInternalFrame[] j = desk.getAllFrames();
                for (int i = 0; i < j.length; i++) {
                    if ("StaffApp".equals(j[i].getName())) {
                        j[i].dispose();
                    }
                }
                JInternalFrame dlgRelApp = new FrmStaffApp(dc, this, (String) staffModel.getValueAt(rowSelected, 1), (String) staffModel.getValueAt(rowSelected, 4));
                desk.add(dlgRelApp);
                dlgRelApp.setVisible(true);
            }
            //Change select to row selected
            if (tblStaff.getSelectedColumn() != 0) {
                for (int i = 0; i < staffModel.getRowCount(); i++) {
                    staffModel.setValueAt(false, i, 0);
                }
                staffModel.setValueAt(true, rowSelected, 0);
            }
            //
            ID = (String) staffModel.getValueAt(rowSelected, 4);
            name = (String) staffModel.getValueAt(rowSelected, 1);
            //Add values to Fields in Details
            if (!isUpdate && !isInsert) {
                txtStaffID_D.setText((String) staffModel.getValueAt(rowSelected, 4));
                txtStaffName_D.setText((String) staffModel.getValueAt(rowSelected, 1));
                txtAddress_D.setText((String) staffModel.getValueAt(rowSelected, 5));
                chkActive.setSelected((boolean) staffModel.getValueAt(rowSelected, 2));
                chkLock.setSelected((boolean) staffModel.getValueAt(rowSelected, 3));
                String imgNameRow = (String) staffModel.getValueAt(rowSelected, 6);
                if (imgNameRow.equalsIgnoreCase("NoImage")) {
                    imgStaff.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/NoImage.jpg")));
                } else {
                    try {
                        Image imgTemp = ImageIO.read(new File("images/Staff_Img/" + imgNameRow));
                        imgStaff.setIcon(new ImageIcon(imgTemp));
                    } catch (Exception e) {
                        imgStaff.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/NoImage.jpg")));
                    }
                }
            }

            //----------------------------------
            // Add values to Specialist List
            if (rowCounter < 2) {
                //btnAddSpec.setEnabled(true);
                sql = "select * from vw_staff_services";
                specModel = new DefaultListModel<>();
                try {
                    rs = stmt.executeQuery(sql);
                    while (rs.next()) {
                        if (rs.getString(1).equalsIgnoreCase(ID)) {
                            specModel.addElement(rs.getString(3));
                        }
                    }
                    lstSpec.setModel(specModel);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            //
        }

    }//GEN-LAST:event_tblStaffMousePressed

    private void btnEmp_AppActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEmp_AppActionPerformed
        JDesktopPane desk = getDesktopPane();
        int line = tblStaff.getSelectedRow();
        line = tblStaff.convertRowIndexToModel(line);

        if (isView) {
            JInternalFrame[] j = desk.getAllFrames();
            for (int i = 0; i < j.length; i++) {
                if ("StaffApp".equals(j[i].getName())) {
                    j[i].setVisible(false);
                    j[i].dispose();
                }
            }
            btnEmp_App.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/001_25.png")));
            isView = false;
        } else {
            JInternalFrame dlgRelApp = new FrmStaffApp(dc, this, (String) staffModel.getValueAt(line, 1), (String) staffModel.getValueAt(line, 4));
            desk.add(dlgRelApp);
            btnEmp_App.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/001_27.png")));
            isView = true;
            dlgRelApp.setVisible(true);
        }

    }//GEN-LAST:event_btnEmp_AppActionPerformed

    private void btnAddImgActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddImgActionPerformed
        try {
            JFileChooser file = new JFileChooser();
            FileFilter filter = new FileNameExtensionFilter("Images file", "jpg", "jpeg", "png");
            file.showOpenDialog(this);
            file.addChoosableFileFilter(filter);

            // Check Image file
            if (filter.accept(file.getSelectedFile())) {

                img = ImageIO.read(file.getSelectedFile());
                if (img.getWidth() != 92 && img.getHeight() != 98) {
                    JOptionPane.showMessageDialog(this, "Image's size must be 92x98 pixels.\nPlease crop it. and add again!", "Warning", JOptionPane.ERROR_MESSAGE);
                } else {
                    imgName = txtStaffID_D.getText() + ".jpg";
                    PictureChanged = true;
                    imgStaff.setIcon(new ImageIcon(file.getSelectedFile().getPath()));
                }

            } else {
                System.out.println(file.getSelectedFile().getName());
                JOptionPane.showMessageDialog(this, "You must choose .jpg or .png image file.\nPlease choose another file");
            }
            //
        } catch (Exception e) {
            System.out.println("No file chosen");
        }
    }//GEN-LAST:event_btnAddImgActionPerformed

    private void btnExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExitActionPerformed
        this.dispose();
    }//GEN-LAST:event_btnExitActionPerformed

    private void btnAddSpecActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddSpecActionPerformed
        int line = tblStaff.getSelectedRow();
        if (line != -1) {
            dlgSpecialist dlgSpec = new dlgSpecialist(null, false, specModel, ID, name, dc);
            dlgSpec.setVisible(true);
        } else {
            JOptionPane.showMessageDialog(this, "Please choose a staff!");
        }


    }//GEN-LAST:event_btnAddSpecActionPerformed

    private void formInternalFrameIconified(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameIconified
        JDesktopPane desk = getDesktopPane();
        JInternalFrame[] j = desk.getAllFrames();

        for (int i = 0; i < j.length; i++) {
            if ("StaffApp".equals(j[i].getName())) {
                j[i].setVisible(false);
            }
        }
    }//GEN-LAST:event_formInternalFrameIconified

    private void formInternalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameDeiconified
        JDesktopPane desk = getDesktopPane();
        JInternalFrame[] j = desk.getAllFrames();

        for (int i = 0; i < j.length; i++) {
            if ("StaffApp".equals(j[i].getName())) {
                j[i].setVisible(true);
            }
        }
    }//GEN-LAST:event_formInternalFrameDeiconified

    private void formInternalFrameClosing(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameClosing
        JDesktopPane desk = getDesktopPane();
        JInternalFrame[] j = desk.getAllFrames();

        for (int i = 0; i < j.length; i++) {
            if ("StaffApp".equals(j[i].getName())) {
                j[i].dispose();
            }
        }
    }//GEN-LAST:event_formInternalFrameClosing

    private void btnSelectAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSelectAllActionPerformed
        for (int i = 0; i < staffModel.getRowCount(); i++) {
            tblStaff.getModel().setValueAt(true, i, 0);
        }
    }//GEN-LAST:event_btnSelectAllActionPerformed

    private void btnDeselectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeselectActionPerformed
        for (int i = 0; i < staffModel.getRowCount(); i++) {
            tblStaff.getModel().setValueAt(false, i, 0);
        }
        tblStaff.getSelectionModel().clearSelection();
        noSelectionState();
    }//GEN-LAST:event_btnDeselectActionPerformed

    private void btnInsertActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnInsertActionPerformed
        openfield("insert");
        if (newID.equals("Emp10000")) {
            JOptionPane.showMessageDialog(this, "Database for employee limit reached.\n Contact us for upgrade version");
            beginState();
        } else {
            txtStaffID_D.setText(newID);
            isInsert = true;
            btnUpdate.setEnabled(false);
            btnInsert.setEnabled(false);
        }
    }//GEN-LAST:event_btnInsertActionPerformed

    private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
        String error = checkField();
        ID = txtStaffID_D.getText();
        if (error.equals("")) {
            // Create New Img File
            if (PictureChanged) {
                File file = new File("images/Staff_Img/" + ID + ".jpg");
                try {
                    if (file.exists()) {
                        file.delete();
                        //file.createNewFile();
                    }
                    ImageIO.write(img, "jpg", file);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            //
            int isLock = chkLock.isSelected() ? 1 : 0;
            int isActive = chkActive.isSelected() ? 1 : 0;

            try {
                if (isInsert) {
                    sql = "Insert into staff(StaffID,StaffName,Addr,Active,isLock,Picture,DateCreated,UserCreated)"
                            + " values ('" + ID + "','"
                            + name + "','"
                            + Addr + "'," + isActive + "," + isLock + ",'" + imgName + "','"
                            + date + "','" + User + "')";
                    // Change Model
                    staffModel.addRow(new Object[]{false, name, isActive == 1, isLock == 1, ID, Addr, imgName});
                }

                if (isUpdate) {
                    // Find Row in staffModel to setValue
                    int row = -1;
                    for (int i = 0; i < staffModel.getRowCount(); i++) {
                        if (staffModel.getValueAt(i, 4).equals(ID)) {
                            row = i;
                        }
                    }
                    //-------------------
                    if (PictureChanged) {
                        sql = "Update staff set StaffName='" + name + "', Addr='" + Addr + "', "
                                + "Active =" + isActive + " ,isLock=" + isLock + ", Picture='" + imgName
                                + "' where StaffID='" + ID + "'";
                        if (row != -1) {
                            staffModel.setValueAt(imgName, row, 6);
                        }
                    } else {
                        sql = "Update staff set StaffName='" + name + "', Addr='" + Addr + "', "
                                + "Active =" + isActive + " ,isLock=" + isLock
                                + " where StaffID='" + ID + "'";
                    }

                    if (row != -1) {
                        staffModel.setValueAt(name, row, 1);
                        staffModel.setValueAt(isActive == 1, row, 2);
                        staffModel.setValueAt(isLock == 1, row, 3);
                        staffModel.setValueAt(ID, row, 4);
                        staffModel.setValueAt(Addr, row, 5);
                    }
                }
                stmt.executeUpdate(sql);
                //----------------------
                beginState();
            } catch (Exception e) {
                e.printStackTrace();
            }

        } else {
            lblDetailsMsg.setText(error);
            return;
        }
    }//GEN-LAST:event_btnSaveActionPerformed

    private void btnDeleteSpecActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteSpecActionPerformed
        int line = lstSpec.getSelectedIndex();
        if (line != -1) {
            List selectedList = lstSpec.getSelectedValuesList();
            for (int i = 0; i < selectedList.size(); i++) {
                specModel.removeElement(selectedList.get(i));
            }
        } else {
            JOptionPane.showMessageDialog(this, "Please choose at least one specialist");
        }
    }//GEN-LAST:event_btnDeleteSpecActionPerformed

    private void lstSpecValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_lstSpecValueChanged
        int line = lstSpec.getSelectedIndex();
        if (line != -1) {
            btnDeleteSpec.setEnabled(true);
        } else {
            btnDeleteSpec.setEnabled(false);
        }
    }//GEN-LAST:event_lstSpecValueChanged

    private void mniUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mniUpdateActionPerformed
        btnUpdateActionPerformed(evt);
    }//GEN-LAST:event_mniUpdateActionPerformed

    private void mniSelectAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mniSelectAllActionPerformed
        btnSelectAllActionPerformed(evt);
    }//GEN-LAST:event_mniSelectAllActionPerformed

    private void mniDeselectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mniDeselectActionPerformed
        btnDeselectActionPerformed(evt);
    }//GEN-LAST:event_mniDeselectActionPerformed

    private void pmnStaffPopupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_pmnStaffPopupMenuWillBecomeVisible
        int row = tblStaff.getSelectedRow();
        mniSelectAll.setEnabled(btnSelectAll.isEnabled());
        mniDeselect.setEnabled(btnDeselect.isEnabled());
        if (row != -1) {
            row = tblStaff.convertRowIndexToModel(row);
            mniAddSpec.setEnabled(true);
            mniUpdate.setEnabled(true);
            if (staffModel.getValueAt(row, 3).equals(true)) {
                mniLock.setEnabled(false);
                mniUnlock.setEnabled(true);
            } else {
                mniLock.setEnabled(true);
                mniUnlock.setEnabled(false);
            }
        } else {
            mniAddSpec.setEnabled(false);
            mniLock.setEnabled(false);
            mniUnlock.setEnabled(false);
            mniUpdate.setEnabled(false);
        }
    }//GEN-LAST:event_pmnStaffPopupMenuWillBecomeVisible

    private void mniAddSpecActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mniAddSpecActionPerformed
        btnAddSpecActionPerformed(evt);
    }//GEN-LAST:event_mniAddSpecActionPerformed

    private void btnFindAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFindAllActionPerformed
        tblStaff.getSelectionModel().clearSelection();
        noSelectionState();
        staffModel.setRowCount(0);
        int isActiveChecked = chkActive_S.isSelected() ? 1 : 0;
        if (isActiveChecked == 1) {
            addTableValue("select * from staff where Active=1");
        } else {
            addTableValue("select * from staff");
        }
    }//GEN-LAST:event_btnFindAllActionPerformed

    private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUpdateActionPerformed
        openfield("");
        isUpdate = true;
        btnInsert.setEnabled(false);
        btnUpdate.setEnabled(false);
    }//GEN-LAST:event_btnUpdateActionPerformed

    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
        beginState();
    }//GEN-LAST:event_btnCancelActionPerformed

    private void radStaffNamePropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_radStaffNamePropertyChange
        boolean isCheck = radStaffName.isSelected();
        txtStaffName_S.setEditable(isCheck);
        txtStaffID_S.setText("");
        btnSearch.setEnabled(false);
    }//GEN-LAST:event_radStaffNamePropertyChange

    private void radStaffIDPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_radStaffIDPropertyChange
        boolean isCheck = radStaffID.isSelected();
        txtStaffName_S.setText("");
        txtStaffID_S.setEditable(isCheck);
        btnSearch.setEnabled(false);
    }//GEN-LAST:event_radStaffIDPropertyChange

    private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchActionPerformed
        String searchID = txtStaffID_S.getText();
        String searchName = txtStaffName_S.getText();
        //int isActive_S = chkActive_S.isSelected()?1:0;
        sql = "Select * from staff where";
        // Generate Sql
        if (!searchID.equals("")) {
            sql += " StaffID='" + searchID + "'";
        }
        if (!searchName.equals("")) {
            sql += " StaffName like '%" + searchName + "%'";
        }
        tblStaff.getSelectionModel().clearSelection();
        noSelectionState();
        staffModel.setRowCount(0);
        addTableValue(sql);
    }//GEN-LAST:event_btnSearchActionPerformed

    private void txtStaffID_SKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtStaffID_SKeyReleased
        btnSearch.setEnabled(!txtStaffID_S.getText().equals(""));
    }//GEN-LAST:event_txtStaffID_SKeyReleased

    private void txtStaffName_SKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtStaffName_SKeyReleased
        btnSearch.setEnabled(!txtStaffName_S.getText().equals(""));
    }//GEN-LAST:event_txtStaffName_SKeyReleased

    private void mniNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mniNewActionPerformed
        btnInsertActionPerformed(evt);
    }//GEN-LAST:event_mniNewActionPerformed

    private void btnLockStaffActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLockStaffActionPerformed
        int ans = JOptionPane.showConfirmDialog(this, "Do you want to lock staff?", "Warning", JOptionPane.YES_NO_OPTION);
        if (ans == JOptionPane.YES_OPTION) {
            ArrayList selectedLine = new ArrayList();
            for (int i = 0; i < staffModel.getRowCount(); i++) {
                if (staffModel.getValueAt(i, 0).equals(true)) {
                    selectedLine.add(i);
                }
            }
            for (int i = 0; i < selectedLine.size(); i++) {
                sql = "Update Staff set isLock=1, Active=0 where StaffID='" + staffModel.getValueAt((int) selectedLine.get(i), 4) + "'";
                try {
                    stmt.executeUpdate(sql);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            beginState();
        } else {
            return;
        }
    }//GEN-LAST:event_btnLockStaffActionPerformed

    private void btnUnlockStaffActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUnlockStaffActionPerformed
        ArrayList selectedLine = new ArrayList();
        for (int i = 0; i < staffModel.getRowCount(); i++) {
            if (staffModel.getValueAt(i, 0).equals(true)) {
                selectedLine.add(i);
            }
        }
        for (int i = 0; i < selectedLine.size(); i++) {
            sql = "Update Staff set isLock=0 where StaffID='" + staffModel.getValueAt((int) selectedLine.get(i), 4) + "'";
            try {
                stmt.executeUpdate(sql);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        beginState();
    }//GEN-LAST:event_btnUnlockStaffActionPerformed
//<editor-fold defaultstate="collapsed" desc="Variable">


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAddImg;
    private javax.swing.JButton btnAddSpec;
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnDeleteSpec;
    private javax.swing.JButton btnDeselect;
    private javax.swing.JButton btnEmp_App;
    private javax.swing.JButton btnExit;
    private javax.swing.JButton btnFindAll;
    private javax.swing.JButton btnInsert;
    private javax.swing.JButton btnLockStaff;
    private javax.swing.JButton btnSave;
    private javax.swing.JButton btnSearch;
    private javax.swing.JButton btnSelectAll;
    private javax.swing.JButton btnUnlockStaff;
    private javax.swing.JButton btnUpdate;
    private javax.swing.JCheckBox chkActive;
    private javax.swing.JCheckBox chkActive_S;
    private javax.swing.JCheckBox chkLock;
    private javax.swing.ButtonGroup grpFilter;
    private javax.swing.JLabel imgStaff;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JSeparator jSeparator;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JPopupMenu.Separator jSeparator2;
    private javax.swing.JScrollPane jspSpec;
    private javax.swing.JScrollPane jspStaff;
    private javax.swing.JLabel lblAddr;
    private javax.swing.JLabel lblDetailsMsg;
    private javax.swing.JLabel lblRequired2;
    private javax.swing.JLabel lblRequired3;
    private javax.swing.JLabel lblSpec;
    private javax.swing.JLabel lblStaffFound;
    private javax.swing.JLabel lblStaffID;
    private javax.swing.JLabel lblStaffName;
    private javax.swing.JLabel lblStatus;
    private javax.swing.JList lstSpec;
    private javax.swing.JMenuItem mniAddSpec;
    private javax.swing.JMenuItem mniDeselect;
    private javax.swing.JMenuItem mniLock;
    private javax.swing.JMenuItem mniNew;
    private javax.swing.JMenuItem mniSelectAll;
    private javax.swing.JMenuItem mniUnlock;
    private javax.swing.JMenuItem mniUpdate;
    private javax.swing.JPopupMenu pmnStaff;
    private javax.swing.JPanel pnlDetails;
    private javax.swing.JPanel pnlDetailsChild;
    private javax.swing.JPanel pnlLookup;
    private javax.swing.JRadioButton radStaffID;
    private javax.swing.JRadioButton radStaffName;
    private javax.swing.JTable tblStaff;
    private javax.swing.JTextField txtAddress_D;
    private javax.swing.JTextField txtStaffID_D;
    private javax.swing.JTextField txtStaffID_S;
    private javax.swing.JTextField txtStaffName_D;
    private javax.swing.JTextField txtStaffName_S;
    // End of variables declaration//GEN-END:variables
//</editor-fold>
//<editor-fold defaultstate="collapsed" desc="Renderer">

    class MyRender implements TableCellRenderer {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            row = table.convertRowIndexToModel(row);
            JTextField editor = new JTextField();
            editor.setBorder(null);
            editor.setText(value.toString());
            editor.setHorizontalAlignment((int) CENTER_ALIGNMENT);
            if (isSelected) {
                if (table.getModel().getValueAt(row, 3).equals(true)) {
                    editor.setBackground(new Color(0, 51, 255));
                    editor.setForeground(Color.WHITE);
                    editor.setFont(getFont().deriveFont(Font.BOLD));
                } else {
                    editor.setBackground(table.getSelectionBackground());
                }

            } else {
                if (table.getModel().getValueAt(row, 3).equals(true)) {

                    editor.setForeground(Color.BLACK);
                    editor.setBackground(Color.LIGHT_GRAY);
                } else {
                    editor.setForeground(Color.BLACK);
                }
            }
            return editor;
        }
    }
//</editor-fold>

}
